<!-- HTML header for doxygen 1.8.20-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=9"/>
	<meta name="generator" content="Doxygen 1.9.4"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>Raspberry Pi Pico SDK: hardware_claim</title>
	<!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="dynsections.js"></script>
	<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
	<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
	<link href="doxygen.css" rel="stylesheet" type="text/css" />
	<link href="normalise.css" rel="stylesheet" type="text/css"/>
<link href="main.css" rel="stylesheet" type="text/css"/>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
	<div class="navigation-mobile">
		<div class="logo--mobile">
			<a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
		</div>
		<div class="navigation-toggle">
			<span class="line-1"></span>
			<span class="line-2">
				<p>Menu Toggle</p>
			</span>
			<span class="line-3"></span>
		</div>
	</div>
	<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
		<div class="logo">
			<a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
			<span style="display: inline-block; margin-top: 10px;">
				v2.0.0
			</span>
		</div>
		<div class="navigation-footer">
			<img src="logo-mobile.svg" alt="Raspberry Pi">
			<a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
		</div>
<!-- 		<div class="search">
			<form>
				<input type="search" name="search" id="search" placeholder="Search">
				<input type="submit" value="Search">
			</form>
		</div> -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('group__hardware__claim.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">hardware_claim<div class="ingroups"><a class="el" href="group__hardware.html">Hardware APIs</a></div></div></div>
</div><!--header-->
<div class="contents">

<p>Lightweight hardware resource management API.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga6487272cf1fa8d5b2e67f78bb5bdab4d"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__claim.html#ga6487272cf1fa8d5b2e67f78bb5bdab4d">hw_claim_or_assert</a> (uint8_t *bits, uint bit_index, const char *message)</td></tr>
<tr class="memdesc:ga6487272cf1fa8d5b2e67f78bb5bdab4d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Atomically claim a resource, panicking if it is already in use.  <a href="group__hardware__claim.html#ga6487272cf1fa8d5b2e67f78bb5bdab4d">More...</a><br /></td></tr>
<tr class="separator:ga6487272cf1fa8d5b2e67f78bb5bdab4d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gacc8b9324cd6f327e57c6dcb8cbef1745"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__claim.html#gacc8b9324cd6f327e57c6dcb8cbef1745">hw_claim_unused_from_range</a> (uint8_t *bits, bool required, uint bit_lsb, uint bit_msb, const char *message)</td></tr>
<tr class="memdesc:gacc8b9324cd6f327e57c6dcb8cbef1745"><td class="mdescLeft">&#160;</td><td class="mdescRight">Atomically claim one resource out of a range of resources, optionally asserting if none are free.  <a href="group__hardware__claim.html#gacc8b9324cd6f327e57c6dcb8cbef1745">More...</a><br /></td></tr>
<tr class="separator:gacc8b9324cd6f327e57c6dcb8cbef1745"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gab3aa24c90859fbc4da40b8fce8852f6e"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__claim.html#gab3aa24c90859fbc4da40b8fce8852f6e">hw_is_claimed</a> (const uint8_t *bits, uint bit_index)</td></tr>
<tr class="memdesc:gab3aa24c90859fbc4da40b8fce8852f6e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Determine if a resource is claimed at the time of the call.  <a href="group__hardware__claim.html#gab3aa24c90859fbc4da40b8fce8852f6e">More...</a><br /></td></tr>
<tr class="separator:gab3aa24c90859fbc4da40b8fce8852f6e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga9291a012435d3efff22c592d47e82b4a"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__claim.html#ga9291a012435d3efff22c592d47e82b4a">hw_claim_clear</a> (uint8_t *bits, uint bit_index)</td></tr>
<tr class="memdesc:ga9291a012435d3efff22c592d47e82b4a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Atomically unclaim a resource.  <a href="group__hardware__claim.html#ga9291a012435d3efff22c592d47e82b4a">More...</a><br /></td></tr>
<tr class="separator:ga9291a012435d3efff22c592d47e82b4a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac322717d266403fac74aed5cef23eb95"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__claim.html#gac322717d266403fac74aed5cef23eb95">hw_claim_lock</a> (void)</td></tr>
<tr class="memdesc:gac322717d266403fac74aed5cef23eb95"><td class="mdescLeft">&#160;</td><td class="mdescRight">Acquire the runtime mutual exclusion lock provided by the <code>hardware_claim</code> library.  <a href="group__hardware__claim.html#gac322717d266403fac74aed5cef23eb95">More...</a><br /></td></tr>
<tr class="separator:gac322717d266403fac74aed5cef23eb95"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae5ebb9e8ede55de49e6296953d731005"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__hardware__claim.html#gae5ebb9e8ede55de49e6296953d731005">hw_claim_unlock</a> (uint32_t token)</td></tr>
<tr class="memdesc:gae5ebb9e8ede55de49e6296953d731005"><td class="mdescLeft">&#160;</td><td class="mdescRight">Release the runtime mutual exclusion lock provided by the <code>hardware_claim</code> library.  <a href="group__hardware__claim.html#gae5ebb9e8ede55de49e6296953d731005">More...</a><br /></td></tr>
<tr class="separator:gae5ebb9e8ede55de49e6296953d731005"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p >Lightweight hardware resource management API. </p>
<p ><code>hardware_claim</code> provides a simple API for management of hardware resources at runtime.</p>
<p >This API is usually called by other hardware specific <em>claiming</em> APIs and provides simple multi-core safe methods to manipulate compact bit-sets representing hardware resources.</p>
<p >This API allows any other library to cooperatively participate in a scheme by which both compile time and runtime allocation of resources can co-exist, and conflicts can be avoided or detected (depending on the use case) without the libraries having any other knowledge of each other.</p>
<p >Facilities are providing for:</p>
<ol type="1">
<li>Claiming resources (and asserting if they are already claimed)</li>
<li>Freeing (unclaiming) resources</li>
<li>Finding unused resources </li>
</ol>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga9291a012435d3efff22c592d47e82b4a" name="ga9291a012435d3efff22c592d47e82b4a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga9291a012435d3efff22c592d47e82b4a">&#9670;&nbsp;</a></span>hw_claim_clear()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void hw_claim_clear </td>
          <td>(</td>
          <td class="paramtype">uint8_t *&#160;</td>
          <td class="paramname"><em>bits</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint&#160;</td>
          <td class="paramname"><em>bit_index</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Atomically unclaim a resource. </p>
<p >The resource ownership is indicated by the bit_index bit in an array of bits.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">bits</td><td>pointer to an array of bits (8 bits per byte) </td></tr>
    <tr><td class="paramname">bit_index</td><td>resource to unclaim (bit index into array of bits) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="gac322717d266403fac74aed5cef23eb95" name="gac322717d266403fac74aed5cef23eb95"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gac322717d266403fac74aed5cef23eb95">&#9670;&nbsp;</a></span>hw_claim_lock()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t hw_claim_lock </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Acquire the runtime mutual exclusion lock provided by the <code>hardware_claim</code> library. </p>
<p >This method is called automatically by the other <code>hw_claim_</code> methods, however it is provided as a convenience to code that might want to protect other hardware initialization code from concurrent use.</p>
<dl class="section note"><dt>Note</dt><dd><a class="el" href="group__hardware__claim.html#gac322717d266403fac74aed5cef23eb95" title="Acquire the runtime mutual exclusion lock provided by the hardware_claim library.">hw_claim_lock()</a> uses a spin lock internally, so disables interrupts on the calling core, and will deadlock if the calling core already owns the lock.</dd></dl>
<dl class="section return"><dt>Returns</dt><dd>a token to pass to <a class="el" href="group__hardware__claim.html#gae5ebb9e8ede55de49e6296953d731005" title="Release the runtime mutual exclusion lock provided by the hardware_claim library.">hw_claim_unlock()</a> </dd></dl>

</div>
</div>
<a id="ga6487272cf1fa8d5b2e67f78bb5bdab4d" name="ga6487272cf1fa8d5b2e67f78bb5bdab4d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga6487272cf1fa8d5b2e67f78bb5bdab4d">&#9670;&nbsp;</a></span>hw_claim_or_assert()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void hw_claim_or_assert </td>
          <td>(</td>
          <td class="paramtype">uint8_t *&#160;</td>
          <td class="paramname"><em>bits</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint&#160;</td>
          <td class="paramname"><em>bit_index</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>message</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Atomically claim a resource, panicking if it is already in use. </p>
<p >The resource ownership is indicated by the bit_index bit in an array of bits.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">bits</td><td>pointer to an array of bits (8 bits per byte) </td></tr>
    <tr><td class="paramname">bit_index</td><td>resource to claim (bit index into array of bits) </td></tr>
    <tr><td class="paramname">message</td><td>string to display if the bit cannot be claimed; note this may have a single printf format "%d" for the bit </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="gae5ebb9e8ede55de49e6296953d731005" name="gae5ebb9e8ede55de49e6296953d731005"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae5ebb9e8ede55de49e6296953d731005">&#9670;&nbsp;</a></span>hw_claim_unlock()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void hw_claim_unlock </td>
          <td>(</td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>token</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Release the runtime mutual exclusion lock provided by the <code>hardware_claim</code> library. </p>
<dl class="section note"><dt>Note</dt><dd>This method MUST be called from the same core that call <a class="el" href="group__hardware__claim.html#gac322717d266403fac74aed5cef23eb95" title="Acquire the runtime mutual exclusion lock provided by the hardware_claim library.">hw_claim_lock()</a></dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">token</td><td>the token returned by the corresponding call to <a class="el" href="group__hardware__claim.html#gac322717d266403fac74aed5cef23eb95" title="Acquire the runtime mutual exclusion lock provided by the hardware_claim library.">hw_claim_lock()</a> </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="gacc8b9324cd6f327e57c6dcb8cbef1745" name="gacc8b9324cd6f327e57c6dcb8cbef1745"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gacc8b9324cd6f327e57c6dcb8cbef1745">&#9670;&nbsp;</a></span>hw_claim_unused_from_range()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int hw_claim_unused_from_range </td>
          <td>(</td>
          <td class="paramtype">uint8_t *&#160;</td>
          <td class="paramname"><em>bits</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>required</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint&#160;</td>
          <td class="paramname"><em>bit_lsb</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint&#160;</td>
          <td class="paramname"><em>bit_msb</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>message</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Atomically claim one resource out of a range of resources, optionally asserting if none are free. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">bits</td><td>pointer to an array of bits (8 bits per byte) </td></tr>
    <tr><td class="paramname">required</td><td>true if this method should panic if the resource is not free </td></tr>
    <tr><td class="paramname">bit_lsb</td><td>the lower bound (inclusive) of the resource range to claim from </td></tr>
    <tr><td class="paramname">bit_msb</td><td>the upper bound (inclusive) of the resource range to claim from </td></tr>
    <tr><td class="paramname">message</td><td>string to display if the bit cannot be claimed </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the bit index representing the claimed or -1 if none are available in the range, and required = false </dd></dl>

</div>
</div>
<a id="gab3aa24c90859fbc4da40b8fce8852f6e" name="gab3aa24c90859fbc4da40b8fce8852f6e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gab3aa24c90859fbc4da40b8fce8852f6e">&#9670;&nbsp;</a></span>hw_is_claimed()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">bool hw_is_claimed </td>
          <td>(</td>
          <td class="paramtype">const uint8_t *&#160;</td>
          <td class="paramname"><em>bits</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint&#160;</td>
          <td class="paramname"><em>bit_index</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Determine if a resource is claimed at the time of the call. </p>
<p >The resource ownership is indicated by the bit_index bit in an array of bits.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">bits</td><td>pointer to an array of bits (8 bits per byte) </td></tr>
    <tr><td class="paramname">bit_index</td><td>resource to check (bit index into array of bits) </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if the resource is claimed </dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->

	<script src="main.js"></script>
</body>
</html>